package com.xhs.hawaii.upload.controller;

import com.xhs.hawaii.upload.model.UploadFile;
import com.xhs.hawaii.upload.service.QCloudService;
import com.xhs.hawaii.upload.service.QiniuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Api(value = "/upload", description = "文件上传服务")
@RequestMapping("/upload")
public class UploadController {

    @Autowired
    private QiniuService qiniuService;
    @Autowired
    private QCloudService qCloudService;

    @ApiOperation("删除文件-公有空间")
    @RequestMapping(value = "/deletePublicFile", method = RequestMethod.POST)
    public void deletePublicFile(String fileKey) {
        qiniuService.deletePublicFile(fileKey);
    }

    @ApiOperation("七牛文件上传-上传至公有空间")
    @RequestMapping(value = "/qiniuUploadToPublic", method = RequestMethod.POST)
    public UploadFile qiniuUploadToPublic(MultipartFile file) {
        return qiniuService.uploadToPublic(file);
    }

    @ApiOperation("七牛文件上传-上传至私有空间")
    @RequestMapping(value = "/qiniuUpload", method = RequestMethod.POST)
    public UploadFile qiniuUpload(MultipartFile file) {
        return qiniuService.upload(file);
    }

    @ApiOperation("七牛获取下载的URL")
    @RequestMapping(value = "/getQiniuDownloadUrl", method = RequestMethod.GET)
    public String getQiniuDownloadUrl(String originUrl) {
        return qiniuService.getDownloadUrl(originUrl, 3600);
    }


    @ApiOperation("腾讯云上传文件")
    @RequestMapping(value = "/qCloudUpload", method = RequestMethod.POST)
    public UploadFile qCloudUpload(MultipartFile file) {
        return qCloudService.qCloudUpload(file);
    }

    @ApiOperation("腾讯云获取下载的URL")
    @RequestMapping(value = "/getQCloudDownloadUrl", method = RequestMethod.GET)
    public String getQCloudDownloadUrl(String originUrl) {
        return qCloudService.getQCloudDownload(originUrl);
    }


}
